package com.btkjgc.service.impl;

import java.util.Date;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import com.btkjgc.models.AdminUser;
import com.btkjgc.models.AjaxObj;
import com.btkjgc.models.ElectricChargingSite;
import com.btkjgc.models.PropertyCompany;
import com.btkjgc.service.intf.PropertyCompanyManageService_Intf;
import com.btkjgc.utils.HibernateUtil;

/**
 * Created by _ESE on 2015/2/9.
 */
@Component
public class PropertyCompanyManageService_Impl extends BaseService_Impl
		implements PropertyCompanyManageService_Intf {

	static Logger logger = Logger.getLogger(PropertyCompanyManageService_Impl.class);

	@SuppressWarnings("unchecked")
	@Override
	public Integer insertPropertyCompany(
			PropertyCompany propertyCompany) {

		ElectricChargingSite electricChargingSite = new ElectricChargingSite();

		try {
 
			propertyCompany.setDel(0);
			propertyCompany.setCreatedate(new Date());
			HibernateUtil.save(propertyCompany);
			return 1;

		} catch (Exception e) {
			return -11;
		}

	}

	@Override
	public void setListData(HttpServletRequest request,ModelAndView mv,int pageIndex, int totalRecord,
			List<PropertyCompany> propertyCompanyList){
		// TODO Auto-generated method stub

		AdminUser adminUser = (AdminUser) request.getSession().getAttribute(
				"user");

		Enumeration<String> names = request.getParameterNames();
		while (names.hasMoreElements()) {
			String name = names.nextElement();
			mv.addObject(name, request.getParameter(name));
		}

		mv.addObject("user_info", adminUser);
		mv.addObject("property_company_list", propertyCompanyList);

		 

		mv.addObject("currentpage", pageIndex);
		mv.addObject("totalRecord", totalRecord);
	}

	@Override
	public AjaxObj updatePropertyCompany(PropertyCompany  propertyCompany) {
		// TODO Auto-generated method stub
		AjaxObj ajaxObj = new AjaxObj();
		ajaxObj.setResult(true);
	 
		try {
			HibernateUtil.executeUpdate(getUpdateHql(propertyCompany));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			ajaxObj.setResult(false);
			ajaxObj.setMsg("更新时发生错误");

		}

		return ajaxObj;
	}

}
